﻿using System;
using System.Collections.Specialized;
using System.IO;
using System.Globalization;
using System.Collections.Generic;

namespace Faml.Sources.T4D
{
    public class T4DFile
    {
        private double[] coords;
        private string[] files;

        public T4DFile(string path)
        {
            List<double> clist = new List<double>();
            List<string> flist = new List<string>();
            string basePath = Path.GetDirectoryName(Path.GetFullPath(path));
            StreamReader sr = new StreamReader(path);
            string line = sr.ReadLine();
            while (line != null && line != "")
            {
                int idx = line.IndexOf(' ');
                if (idx < 1)
                    throw new Exception("Syntax error in " + path);
                clist.Add(double.Parse(line.Substring(0, idx), CultureInfo.InvariantCulture));
                flist.Add(Path.Combine(basePath,line.Substring(idx + 1).Trim()));
                line = sr.ReadLine();
            }
            coords = clist.ToArray();
            files = flist.ToArray();
        }

        public double[] Grid
        {
            get
            {
                return coords;
            }
        }

        public string[] Files
        {
            get
            {
                return files;
            }
        }
    }
}